<?php include '../../authorization_check.php' ?>
<?php include '../../checkSecretaryOnly.php' ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>Search Staff</title>

<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>

</head>

<body>

<?php include 'top.html' ?>
<?php
  session_start();
  $programCode = $_SESSION['programCode'];
  $semesterID = $_SESSION['semesterID'];
?>

<FORM NAME ="form1" METHOD ="POST" ACTION = "ViewStaff.php">
<p>Enter personnel ID to see the details of the personnel: </p>
<p dir="ltr">
Personnel ID: <input type="text" name="textID" size="10" maxlength="7" onKeyPress="return numbersonly(this, event)">
<input type="submit" value="View" name="btnSubmitID" onClick="return textboxControl(textID.value)">
<input type="reset" value="Reset" name="btnResetID">
</p> 
</FORM>

<hr>
<p> <b>OR</b></p>
<hr>
<?php 

if (isset($_POST['btnSubmitNames'])) {
	$surname = $_POST['textSurname'];
	$name = $_POST['textName'];
}

?>


<FORM NAME ="form2" METHOD ="POST" ACTION = "SearchStaffforView.php">
<p>Enter name or surname (or both) of the personnel: </p>
<p dir="ltr">
Name: <input style="text-transform: uppercase" type="text" maxlength="50" name="textName" size="20" value="<?php echo $name ?>" >
Surname: <input style="text-transform: uppercase" type="text" maxlength="50" name="textSurname" size="20" value="<?php echo $surname ?>"> 

<input type="submit" value="Search" name="btnSubmitNames">
<input type="reset" value="Reset" name="btnResetNames">
</p> 
</FORM>

<hr>

<FORM NAME ="form3" METHOD ="POST" ACTION = "ViewStaff.php">
<p>


<?php 
require_once '../../commonutils/db/DBConnectionManager.php';
if (isset($_POST['btnSubmitNames'])) {
	
	echo "<p>";
	echo "<table border=1 cellpadding=3 >";
	echo "<tr>";
	echo "<th>PERSONNEL ID</th>";
	echo "<th>NAME</th>";
	echo "<th>SURNAME</th>";
	echo "</tr>";	
	
	$sqlquery = " select instructorID as personnelID, firstName, lastName from instructor ".
				" where firstName like '%".$name."%' and lastName like '%".$surname."%' ".
				" union ".
				" select personnelID, firstName, lastName from personnel ".
				" where firstName like '%".$name."%' and lastName like '%".$surname."%' ";
	
	$result = DBConnectionManager::query($sqlquery);
		
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td><input type=\"radio\" name=\"personnelID\" value= \"".$row['personnelID']."\">".$row['personnelID']."</td>";
		echo "<td>".$row['firstName']."</td>";
		echo "<td>".$row['lastName']."</td>";
		echo "</tr>";		
	}
	echo "</p>";
	echo "<br>";
	
	echo "</table>";
	
	echo "<p>";
	echo "<input type=\"submit\" value=\"View\" name=\"btnSubmitRadio\">";
	echo "<input type=\"reset\" value=\"Reset\" name=\"btnResetRadio\">";
	echo "</p>";
	
}

if(isset($_POST['personnelIDRadio'])) {
	$personnelID= $_POST['personnelIDRadio'];
}

?>


</p>
 
</FORM>

<?php include 'bottom.php' ?>


</body>

</html>
